<admintpl file="header" />
</head>
<body>
	<div class="wrap js-check-wrap">
		<ul class="nav nav-tabs">
			<li><a href="{:U('Match/index')}">{:L('MATCH_INDEX')}</a></li>
			<li class="active"><a href="{:U('Match/add')}">{:L('MATCH_ADD')}</a></li>
		</ul>
		<form action="" method="post" class="form-horizontal js-ajax-forms">
			<div class="row-fluid">
				<div class="span9">
					<table class="table table-bordered">
						<tr>
							<th width="80">比赛名称</th>
							<td>
								<input type="text" style="width: 400px;" name="name" id="title" value="" placeholder="请输入比赛名称"/>
							</td>
						</tr>
						<tr>
							<th>时间</th>
							<td>
								<select id="timeSelect" style="width: 120px;" name="time"></select>&nbsp;&nbsp;
							</td>
						</tr>
					</table>
				</div>
			</div>
			<div class="form-actions">
				<button class="btn btn-primary js-ajax-submit" type="submit">添加</button>
				<a class="btn" href="javascript:history.back(-1);">返回</a>
			</div>
		</form>
	</div>
	<script type="text/javascript" src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/layer/layer.js"></script>

	<script type="text/javascript">
		$(function() {
			//初始化时间
			var thisYear=new Date().getUTCFullYear();
			var startYear;
			for(startYear=thisYear-10;startYear<thisYear+10;startYear++){
				if(startYear!=thisYear){
					$("#timeSelect").append("<option>"+startYear+"</option>");
				}else{
					$("#timeSelect").append("<option selected='selected'>"+startYear+"</option>");
				}
			}
		});
		$("form").submit(function(e){
			var name=$.trim($("#title").val());
			var a=document.getElementById("timeSelect");
			var time=a.options[a.selectedIndex].value;
			if(name==""){
				layer.msg("比赛名称不能为空",{time:500});
				return;
			}
			if(time==""){
				layer.msg("比赛时间必须选择",{time:500});
				return;
			}

			$.ajax({
				type: "POST",
				url: "{:U('Match/add')}",
				data: {name:name,time:time},
				success: function(result) {
					var result=eval("("+result+")");
					if(result.status){
						layer.msg('添加成功',{time:500},function(){
							location.href = "{:U('Match/index')}";
						});
					}else{
						layer.msg(result.message);
					}
				}
			});
			return false;
		});
	</script>
</body>
</html>